/**
 * problem_030.cpp
 * Copyright (C) 2011 - xrose
 */

#include <iostream>
#include <math.h>
using namespace std;
int power5digit(int n)
{
    int rem;
    int rst = 0;
    while (n>0)
    {
        rem = n%10;
        rst = rst + pow(rem, 5);
        n=(n-rem)/10;
    }
    return rst;
}

int main (int argc, char const* argv[])
{
    int n = 0;
    int sum = 0;
    while(n<=354294)
    {
        if(power5digit(n) == n)
        {
            cout<<"n = "<<n<<endl;
            sum+=n;
            n++;
        } else
        {
            n++;
        }
    }
    cout <<"sum = "<<sum<<endl;
    return 0;
}

